package com.iaic.test;
import javax.rules.*;
import javax.rules.admin.*;
import java.util.HashMap;
import java.io.FileReader;
import jess.*;
import jess.jsr94.RuleServiceProviderImpl;


public class ExJSR94Register {
  public static final String URI = "rules://test-rules";
  public static final String RULE_SERVICE_PROVIDER = "jess.jsr94";

  public static void main(String[] argv) throws Exception {
    // Load the rule service provider.
    // Loading this class will automatically register this
    // provider with the provider manager.
    Class.forName(RULE_SERVICE_PROVIDER + ".RuleServiceProviderImpl");

    // Get the rule service provider from the provider manager.
    RuleServiceProvider serviceProvider =
        RuleServiceProviderManager.getRuleServiceProvider(RULE_SERVICE_PROVIDER);

    // get the RuleAdministrator
    RuleAdministrator ruleAdministrator =
        serviceProvider.getRuleAdministrator();

    // get an input stream to a ruleset
    FileReader reader = new FileReader("/jessRules.clp");

    // parse the ruleset
    try {
        // "properties" holds vendor-specific information
        // Jess doesn't use this parameter for these methods
        HashMap properties = new HashMap();

        // Create the RuleExecutionSet
        RuleExecutionSet executionSet =
            ruleAdministrator.getLocalRuleExecutionSetProvider(properties).
            createRuleExecutionSet(reader, properties);

        // register the RuleExecutionSet
        ruleAdministrator.registerRuleExecutionSet(URI,
                                                   executionSet, properties);

    } finally {
        reader.close();
    }
  }
}

